import { classicBeh } from '../classic-beh.js'

const mMgr = wx.getBackgroundAudioManager()

Component({
  behaviors: [classicBeh],//可以继承多个 behavior
  properties: {

  },
  data: {
    pauseSrc: 'images/player@waitting.png',
    playSrc: 'images/player@playing.png',
    playing: false
  },
  methods: {
    onClickPlay:function(event){
      mMgr.src = this.properties.url
      mMgr.title = 'chanchaw'
      mMgr.loop = true

      if(this.data.playing){
        mMgr.pause()
        console.log('暂停播放')
      }else{
        mMgr.play()
        console.log('播放')
      }
      this.setData({
        playing: !this.data.playing
      })

      mMgr.onPlay(()=>{
        console.log('开始播放了')
        this.setData({
          playing: true
        })
      })

      mMgr.onPause(()=>{
        console.log('暂停播放')
        this.setData({
          playing: false
        })
      })

      mMgr.onEnded(() => {
        console.log('播放自动结束了')
        this.setData({
          playing: false
        })
      })

      mMgr.onStop(()=>{
        console.log('关闭来了系统自带的乐音控制面板')
      })
    }
  }
})
